﻿/***

    应用程序的系统菜单更改操作类库

    Austin Liu 刘恒辉
    Project Manager and Software Designer

    E-Mail: lzhdim@163.com
    Blog:   http://lzhdim.cnblogs.com
    Date:   2024-01-15 15:18:00

***/

namespace Lzhdim.MenuHelper
{
    using System;
    using System.Runtime.InteropServices;

    /// <summary>
    /// 系统菜单管理器
    /// </summary>
    public class SystemMenu
    {
        public const Int32 MF_BYPOSITION = 0x400;

        public const Int32 MF_SEPARATOR = 0x800;

        public const Int32 MF_STRING = 0x0;

        public const Int32 WM_SYSCOMMAND = 0x112;

        /// <summary>
        /// 删除菜单项
        ///
        /// 6　close,　5　splite　line,　4　Maximize,　3　Minimize,　2　Size,　1　Move,　0　Restore
        /// </summary>
        /// <param name="hMenu"></param>
        /// <param name="uPosition"></param>
        /// <param name="uFlags"></param>
        /// <returns></returns>
        [DllImport("user32.dll")]
        public static extern bool DeleteMenu(IntPtr hMenu, uint uPosition, uint uFlags);

        /// <summary>
        /// 获取系统菜单
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="bRevert"></param>
        /// <returns></returns>
        [DllImport("user32.dll")]
        public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

        /// <summary>
        /// 插入菜单项
        /// </summary>
        /// <param name="hMenu"></param>
        /// <param name="wPosition"></param>
        /// <param name="wFlags"></param>
        /// <param name="wIDNewItem"></param>
        /// <param name="lpNewItem"></param>
        /// <returns></returns>
        [DllImport("user32.dll")]
        public static extern bool InsertMenu(IntPtr hMenu, Int32 wPosition, Int32 wFlags, Int32 wIDNewItem, string lpNewItem);
    }
}